//
//  Adventure_TableViewCell.m
//  Food
//
//  Created by dlios on 15-7-14.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Adventure_TableViewCell.h"
#import "UIImageView+WebCache.h"
#import "BaseHeader.h"

@implementation Adventure_TableViewCell
- (void)dealloc
{
    [_titleImage release];
    [_title release];
    [_content release];
    [_backImage release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backGround.jpg"]];
        UIImage *image = [UIImage imageNamed:@"新鲜事背景"];
        self.backImage = [[UIImageView alloc] init];
        self.backImage.image = image;
        [self.contentView addSubview:self.backImage];
        [_backImage release];
        
        self.titleImage = [[UIImageView alloc] init];
        [self.backImage addSubview:self.titleImage];
        [_titleImage release];
        
        self.title = [[UILabel alloc] init];
        [self.title setFont:[UIFont systemFontOfSize:15]];
        [self.backImage addSubview:self.title];
        [_title release];
        
        self.content = [[UILabel alloc] init];
        [self.content setFont:[UIFont systemFontOfSize:13]];
        self.content.numberOfLines = 2;
        [self.backImage addSubview:self.content];
        [_content release];
    }
    return self;
}

- (void)setAdventure:(AdventureModel *)adventure
{
    if (_adventure != adventure) {
        [_adventure release];
        _adventure = [adventure retain];
    }
    [self.titleImage sd_setImageWithURL:[NSURL URLWithString:adventure.titleImageFile]];
    self.title.text = adventure.name;
    self.content.text = adventure.content;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titleImage.frame = CGRectMake(200.0 / 375 *ScreenWidth, 8, 150.0 / 375 *ScreenWidth, 100.0 / 375 *ScreenWidth);
    self.title.frame = CGRectMake(15, 20 / 375.0 * ScreenWidth, 185.0 / 375 *ScreenWidth - 15, 30.0 / 375 *ScreenWidth);
    self.content.frame = CGRectMake(15, 50.0 / 375 *ScreenWidth, 185.0 / 375 *ScreenWidth - 15, 60.0 / 375 *ScreenWidth);
    self.backImage.frame = CGRectMake(5 / 375.0 *ScreenWidth, 5 / 375.0 *ScreenWidth, ScreenWidth - 10 / 375.0 *ScreenWidth, self.titleImage.frame.size.height + 15 / 375.0 *ScreenWidth);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
